//
//  ESGTeamInquiryViewCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/4/8.
//  Copyright © 2020 QDSG. All rights reserved.
//

import UIKit

class ESGTeamInquiryViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        contentView.layer.masksToBounds = true
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        containerView.backgroundColor = selected ? .mainLight : .white
        if selected {
            UIView.animate(withDuration: 0.15) {
                self.setSelected(false, animated: false)
            }
        }
    }
    
    func configure(with vm: ESGTeamInquiryViewModel.RowViewModel) {
        avatarView.kf.setImage(with: URL(string: vm.avatarSD),
                               placeholder: UIImage(named: "avatar_default"))
        teamNameLabel.text = vm.teamName
        nameLabel.text = "负责人：\(vm.teamLeaderName)"
        officeLabel.text = vm.teamLeaderOffice
        specialtyLabel.text = vm.specialty
        scoreLabel.text = vm.score
        scoreView.currentStarCount = vm.score.floatValue
    }
    
    @IBOutlet private weak var containerView: UIView! {
        didSet {
            containerView.layer.cornerRadius = 16
            containerView.layer.masksToBounds = true
        }
    }
    
    @IBOutlet private weak var avatarView: UIImageView! {
        didSet {
            avatarView.contentMode = .scaleAspectFill
            avatarView.layer.cornerRadius = avatarView.height / 2
            avatarView.layer.masksToBounds = true
        }
    }
    
    @IBOutlet private weak var teamNameLabel: UILabel! {
        didSet {
            teamNameLabel.textColor = .textDark
            teamNameLabel.font = .medium_18
        }
    }
    
    @IBOutlet private weak var nameLabel: UILabel! {
        didSet {
            nameLabel.textColor = .textDark
            nameLabel.font = .medium_14
        }
    }
    
    @IBOutlet private weak var officeLabel: UILabel! {
        didSet {
            officeLabel.textColor = .textDark
            officeLabel.font = .medium_14
        }
    }
    
    @IBOutlet private weak var scoreLabel: UILabel!
    
    @IBOutlet private weak var scoreView: StarRatingView! {
        didSet {
            scoreView.backgroundColor = .clear
        }
    }
    
    @IBOutlet private weak var specialtyLabel: UILabel! {
        didSet {
            specialtyLabel.textColor = .textLight
            specialtyLabel.font = .regular_14
        }
    }
}
